package com.baitiaojun.common.enums.impl;

import cn.hutool.core.util.ArrayUtil;
import com.baitiaojun.common.enums.Enums;
import lombok.AllArgsConstructor;

import java.util.Arrays;

/**
 * 业务类型
 */
@AllArgsConstructor
public enum ServiceTypeEnums implements Enums {

    OTHER(0, "其它"),
    INSERT(1, "新增"),
    UPDATE(2, "修改"),
    DELETE(3, "删除"),
    GRANT(4, "授权"),
    EXPORT(5, "导出"),
    IMPORT(6, "导入"),
    FORCE(7, "强退"),
    GENCODE(8, "生成代码"),
    CLEAN(9, "清空数据");

    private final Integer code;

    private final String name;

    @Override
    public Enums valueOf(Integer code) {
        return ArrayUtil.firstMatch(item -> item.getCode().equals(code), values());
    }

    @Override
    public int[] array() {
        return Arrays.stream(values()).mapToInt(ServiceTypeEnums::getCode).toArray();
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getName() {
        return name;
    }
}
